﻿Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Text
Imports System.Data
Imports MySql.Data.MySqlClient
Imports System.Net.Mail
Partial Class ImportLog
    Inherits System.Web.UI.Page

    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Dim dt As DataTable
        Dim dao As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO("AUOOAMS")
        dt = dao.GetAssetData("", "", "", "", "", "", "", "", "")
        Dim vo As AssetManage.VO.AssetVO
        Dim uDao As OAMS.DAO.UsersDAO = New OAMS.DAO.UsersDAO("AUOOAMS")
        Dim dr2 As DataRow
        Dim dtLog As DataTable = GetLogData()
      
        For Each dr As DataRow In dt.Rows

            If dtLog.Select("asset_serialNo='" + dr("asset_serialNo").ToString + "'").Length > 0 Then ''如果有資料就不做
                Continue For
            End If
            vo = New AssetManage.VO.AssetVO()
            vo.asset_serialNo = dr("asset_serialNo").ToString
            vo.assetdef_id = dr("assetdef_id").ToString
            vo.asset_owner = dr("asset_owner").ToString

            vo.asset_status = dr("asset_status").ToString
            Try
                dr2 = uDao.GetEmpData(dr("asset_owner").ToString).Rows(0)
                vo.Dept = dr2("Dept_ID").ToString()
                vo.EXt = dr2("Ext_no").ToString()
            Catch ex As Exception

            End Try

            vo.MAC1 = dr("MAC1").ToString
            vo.MAC2 = dr("MAC2").ToString
            vo.Factory = dr("Factory").ToString
            vo.Class1 = dr("Class").ToString
            vo.Location = dr("Location").ToString

            vo.HouseID = "1"

            vo.ComputerName = dr("ComputerName").ToString
            vo.Model = dr("Model").ToString
            vo.CPU = dr("CPU").ToString
            vo.CD_R = dr("CD_R").ToString
            vo.CD_RW = dr("CD_RW").ToString
            vo.RAM = dr("RAM").ToString
            vo.OS = dr("OS").ToString
            vo.HDD = dr("HDD").ToString
            vo.UsingType = dr("UsingType").ToString
            vo.MonitorSize = dr("MonitorSize").ToString
            vo.StoreLocation = dr("StoreLocation").ToString
            vo.storehouse = dr("StoreHouse").ToString
            vo.UsingType2 = dr("UsingType2").ToString
            vo.PS = dr("PS").ToString
            vo.Remark = dr("Remark").ToString



            vo.User1 = dr("User1").ToString
            vo.OtherRemark = dr("OtherRemark").ToString
            vo.NBLabel = dr("NBLabel").ToString
            vo.FDD = dr("FDD").ToString
            vo.UsingDesc = dr("UsingDesc").ToString

            InsertAssetLog(vo, "0")

        Next
        Response.Write("已全部匯入完畢")
    End Sub
    Public Function MyConn(ByVal Param1 As String) As SqlConnection
        Dim dbName As String = DBSetting.GetDBName(Param1, "", "")
        Dim myConn__1 As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings(dbName).ConnectionString)
        Return myConn__1
    End Function
    Public Function myMYSqlConn(ByVal Param1 As String) As MySql.Data.MySqlClient.MySqlConnection

        Dim mysqlConn1 As New MySql.Data.MySqlClient.MySqlConnection(System.Configuration.ConfigurationManager.AppSettings(Param1))


        Return mysqlConn1
    End Function

    Public Function GetLogData() As DataTable




        Dim cmd As MySqlCommand
        Dim con As MySqlConnection = myMYSqlConn("AUOOAMS")

        Try
            con.Open()

            Dim sb As New StringBuilder()
           
            sb.AppendLine("Select Asset_serialNo from v_ast_assetAllLog where ModiType='0' ")


            cmd = New MySqlCommand(sb.ToString(), con)

            Dim oDbAdapter As MySqlDataAdapter
            oDbAdapter = New MySqlDataAdapter(cmd)
            Dim oTable As Data.DataTable
            oTable = New Data.DataTable()
            oDbAdapter.Fill(oTable)
            con.Close()
            Return oTable

        Catch ex As Exception
            con.Close()
            Throw ex
        Finally


        End Try
    End Function
    Public Sub InsertAssetLog(ByVal vo As AssetManage.VO.AssetVO, ByVal ModiType As String)
        Dim doChgOwner As Boolean = False
        Dim sb As New StringBuilder()
        Dim sqlParams As SqlParameter() = New SqlParameter(1) {}
        Dim ownerOld As String = ""

        sb.AppendLine("select * from  V_AST_ASSETALL  where asset_serialNo=@asset_serialNo ")
        '===========================.



        sqlParams(0) = New SqlParameter("@asset_serialNo", SqlDbType.NVarChar, vo.asset_serialNo.Length)
        sqlParams(0).Value = vo.asset_serialNo

        Dim dr As DataRow = SqlHelper.ExecuteDataset(MyConn("AUOOAMS"), CommandType.Text, sb.ToString(), sqlParams).Tables(0).Rows(0)
        ''新增到mySql中
        Dim cmd As MySqlCommand
        Dim con As MySqlConnection = myMYSqlConn("AUOOAMS")
        Dim sb1 As New StringBuilder()

        Dim oTable As Data.DataTable
        


        Try
            con.Open()
            sb1.AppendLine(" select max(SeqNo)+1 as MAX1 from v_ast_assetalllog where asset_serialNo=?asset_serialNo ")



            cmd = New MySqlCommand(sb1.ToString(), con)
            cmd.Parameters.AddWithValue("?asset_serialNo", vo.asset_serialNo)
            Dim oDbAdapter As MySqlDataAdapter
            oDbAdapter = New MySqlDataAdapter(cmd)
            oTable = New Data.DataTable()
            oDbAdapter.Fill(oTable)
            Dim max As Integer
            If oTable.Rows(0)("MAX1").ToString <> "" Then
                max = Integer.Parse(oTable.Rows(0)("MAX1").ToString)
            Else
                max = 1
            End If

            sb1.Length = 0
            Dim field As String = "asset_serialNo, ModiType, SeqNo,ModiUID,ModiDate"
            Dim field1 As String = "?asset_serialNo,?ModiType,?SeqNo,?ModiUID,?ModiDate"

            If vo.assetdef_idChg Then
                field += ",assetdef_id"
                field1 += ",?assetdef_id"
            End If
            If vo.asset_ownerChg Then
                field += ",asset_owner"
                field1 += ",?asset_owner"
            End If
            If vo.asset_statusChg Then
                field += ",asset_status"
                field1 += ",?asset_status"
            End If

            'If dr("asset_cdate").ToString.Trim <> vo.asset_cdate.Trim() Then
            '    field += ",asset_cdate"
            '    field1 += ",?asset_cdate"
            'End If

            If vo.ClassChg Then
                field += ",Class"
                field1 += ",?Class"
            End If


            'If dr("AssetNumber").ToString.Trim <> vo.AssetNumber.Trim() Then
            '    field += ",AssetNumber"
            '    field1 += ",?AssetNumber"
            'End If
            'If dr("Ownerid").ToString.Trim <> vo.Ownerid.Trim() Then
            '    field += ",Ownerid"
            '    field1 += ",?Ownerid"
            'End If
            If vo.EXtChg Then
                field += ",EXt"
                field1 += ",?EXt"
            End If
            If vo.User1Chg Then
                field += ",User1"
                field1 += ",?User1"
            End If
            If vo.DeptChg Then
                field += ",Dept"
                field1 += ",?Dept"
            End If
            If vo.LocationChg Then
                field += ",Location"
                field1 += ",?Location"
            End If

            If vo.ComputerNameChg Then
                field += ",ComputerName"
                field1 += ",?ComputerName"
            End If

            If vo.ModelChg Then
                field += ",Model"
                field1 += ",?Model"
            End If
            If vo.CPUChg Then
                field += ",CPU"
                field1 += ",?CPU"
            End If


            If vo.FDDChg Then
                field += ",FDD"
                field1 += ",?FDD"
            End If


            If vo.CD_RChg Then
                field += ",CD_R"
                field1 += ",?CD_R"
            End If

            If vo.CD_RWChg Then
                field += ",CD_RW"
                field1 += ",?CD_RW"
            End If
            If vo.MAC1Chg Then
                field += ",MAC1"
                field1 += ",?MAC1"
            End If
            If vo.MAC2Chg Then
                field += ",MAC2"
                field1 += ",?MAC2"
            End If
            If vo.PSChg Then
                field += ",PS"
                field1 += ",?PS"
            End If

            If vo.NBLabelChg Then
                field += ",NBLabel"
                field1 += ",?NBLabel"
            End If
            'If dr("Mail").ToString.Trim <> vo.Mail.Trim() Then
            '    field += ",Mail"
            '    field1 += ",?Mail"
            'End If
            If vo.RemarkChg Then
                field += ",Remark"
                field1 += ",?Remark"
            End If
            If vo.OSChg Then
                field += ",OS"
                field1 += ",?OS"
            End If
            If vo.HDDChg Then
                field += ",HDD"
                field1 += ",?HDD"
            End If
            If vo.RAMChg Then
                field += ",RAM"
                field1 += ",?RAM"
            End If
            If vo.UsingTypeChg Then
                field += ",UsingType"
                field1 += ",?UsingType"
            End If

            If vo.MonitorSizeChg Then
                field += ",MonitorSize"
                field1 += ",?MonitorSize"
            End If
            If vo.FactoryChg Then
                field += ",Factory"
                field1 += ",?Factory"
            End If



            If vo.StoreLocationChg Then
                field += ",StoreLocation"
                field1 += ",?StoreLocation"
            End If

            If vo.UsingType2Chg Then
                field += ",UsingType2"
                field1 += ",?UsingType2"
            End If

            If vo.HouseIDChg Then
                field += ",HouseID"
                field1 += ",?HouseID"
            End If
            If vo.OtherRemarkChg Then
                field += ",OtherRemark"
                field1 += ",?OtherRemark"
            End If
            If vo.Asset_CostChg Then
                field += ",Asset_Cost"
                field1 += ",?Asset_Cost"
            End If
            If vo.UsingDescChg Then
                field += ",UsingDesc"
                field1 += ",?UsingDesc"
            End If
            ''=================================================5/10
            If dr("assetdef_id").ToString.Trim <> vo.assetdef_id.Trim Then
                field += ",assetdef_idChg"
                field1 += ",?assetdef_idChg"
            End If
            If dr("asset_owner").ToString.Trim <> vo.asset_owner.Trim Then
                field += ",asset_ownerChg"
                field1 += ",?asset_ownerChg"
                doChgOwner = True
                ownerOld = dr("asset_owner").ToString.Trim()
                If ModiType = "1" Then
                    ModiType = "2"
                End If
            End If
            If dr("asset_status").ToString.Trim <> vo.asset_status.Trim Then
                field += ",asset_statusChg"
                field1 += ",?asset_statusChg"
            End If



            If dr("Class").ToString.Trim <> vo.Class1.Trim Then
                field += ",ClassChg"
                field1 += ",?ClassChg"
            End If



            If dr("EXt").ToString.Trim <> vo.EXt.Trim Then
                field += ",EXtChg"
                field1 += ",?EXtChg"
            End If
            If dr("User1").ToString.Trim <> vo.User1.Trim Then
                field += ",User1Chg"
                field1 += ",?User1Chg"
            End If
            If dr("Dept").ToString.Trim <> vo.Dept.Trim Then
                field += ",DeptChg"
                field1 += ",?DeptChg"
            End If
            If dr("Location").ToString.Trim <> vo.Location.Trim Then
                field += ",LocationChg"
                field1 += ",?LocationChg"
            End If

            If dr("ComputerName").ToString.Trim <> vo.ComputerName.Trim Then
                field += ",ComputerNameChg"
                field1 += ",?ComputerNameChg"
            End If

            If dr("Model").ToString.Trim <> vo.Model.Trim Then
                field += ",ModelChg"
                field1 += ",?ModelChg"
            End If
            If dr("CPU").ToString.Trim <> vo.CPU.Trim Then
                field += ",CPUChg"
                field1 += ",?CPUChg"
            End If


            If dr("FDD").ToString.Trim <> vo.FDD.Trim Then
                field += ",FDDChg"
                field1 += ",?FDDChg"
            End If


            If dr("CD_R").ToString.Trim <> vo.CD_R.Trim Then
                field += ",CD_RChg"
                field1 += ",?CD_RChg"
            End If

            If dr("CD_RW").ToString.Trim <> vo.CD_RW.Trim Then
                field += ",CD_RWChg"
                field1 += ",?CD_RWChg"
            End If
            If dr("MAC1").ToString.Trim <> vo.MAC1.Trim Then
                field += ",MAC1Chg"
                field1 += ",?MAC1Chg"
            End If
            If dr("MAC2").ToString.Trim <> vo.MAC2.Trim Then
                field += ",MAC2Chg"
                field1 += ",?MAC2Chg"
            End If
            If dr("PS").ToString.Trim <> vo.PS.Trim Then
                field += ",PSChg"
                field1 += ",?PSChg"
            End If

            If dr("NBLabel").ToString.Trim <> vo.NBLabel.Trim Then
                field += ",NBLabelChg"
                field1 += ",?NBLabelChg"
            End If

            If dr("Remark").ToString.Trim <> vo.Remark.Trim Then
                field += ",RemarkChg"
                field1 += ",?RemarkChg"
            End If
            If dr("OS").ToString.Trim <> vo.OS.Trim Then
                field += ",OSChg"
                field1 += ",?OSChg"
            End If
            If dr("HDD").ToString.Trim <> vo.HDD.Trim Then
                field += ",HDDChg"
                field1 += ",?HDDChg"
            End If
            If dr("RAM").ToString.Trim <> vo.RAM.Trim Then
                field += ",RAMChg"
                field1 += ",?RAMChg"
            End If
            If dr("UsingType").ToString.Trim <> vo.UsingType.Trim Then
                field += ",UsingTypeChg"
                field1 += ",?UsingTypeChg"
            End If

            If dr("MonitorSize").ToString.Trim <> vo.MonitorSize.Trim Then
                field += ",MonitorSizeChg"
                field1 += ",?MonitorSizeChg"
            End If
            If dr("Factory").ToString.Trim <> vo.Factory.Trim Then
                field += ",FactoryChg"
                field1 += ",?FactoryChg"
            End If

            If dr("storehouse").ToString.Trim <> vo.storehouse.Trim Then
                field += ",storehouseChg"
                field1 += ",?storehouseChg"
            End If

            If dr("StoreLocation").ToString.Trim <> vo.StoreLocation.Trim Then
                field += ",StoreLocationChg"
                field1 += ",?StoreLocationChg"
            End If

            If dr("UsingType2").ToString.Trim <> vo.UsingType2.Trim Then
                field += ",UsingType2Chg"
                field1 += ",?UsingType2Chg"
            End If

            If dr("HouseID").ToString.Trim <> vo.HouseID.Trim Then
                field += ",HouseIDChg"
                field1 += ",?HouseIDChg"
            End If
            If dr("OtherRemark").ToString.Trim <> vo.OtherRemark.Trim Then
                field += ",OtherRemarkChg"
                field1 += ",?OtherRemarkChg"
            End If
            If dr("Asset_Cost").ToString.Trim <> vo.Asset_Cost.Trim Then
                field += ",Asset_CostChg"
                field1 += ",?Asset_CostChg"
            End If

            If dr("UsingDesc").ToString.Trim <> vo.UsingDesc.Trim Then
                field += ",UsingDescChg"
                field1 += ",?UsingDescChg"
            End If
            If doChgOwner Then
                field += ",FromDept,Fromasset_owner"
                field1 += ",?FromDept,?Fromasset_owner"
            End If
            sb1.AppendLine(" insert into v_ast_assetalllog (" + field + ") values (" + field1 + ")")


            cmd = New MySqlCommand(sb1.ToString(), con)
            cmd.Parameters.AddWithValue("?asset_serialNo", vo.asset_serialNo)

            'If ModiType = "1" Then
            '    If doChgOwner Then
            '        If vo.asset_status = "Scrapped" Then
            '            cmd.Parameters.AddWithValue("?ModiType", "7")
            '        Else
            '            If vo.asset_status = "Storing" Then
            '                cmd.Parameters.AddWithValue("?ModiType", "4")
            '            Else
            '                cmd.Parameters.AddWithValue("?ModiType", "2")
            '            End If

            '        End If

            '    Else
            '        If vo.asset_status = "Scrapped" Then
            '            cmd.Parameters.AddWithValue("?ModiType", "7")
            '        Else
            '            If vo.asset_status = "Storing" Then
            '                cmd.Parameters.AddWithValue("?ModiType", "4")
            '            Else
            '                cmd.Parameters.AddWithValue("?ModiType", "1")
            '            End If
            '        End If
            '    End If
            'Else
            '    If doChgOwner Then
            '        If vo.asset_status = "Storing" Then
            '            cmd.Parameters.AddWithValue("?ModiType", "4")
            '        Else
            '            cmd.Parameters.AddWithValue("?ModiType", "2")
            '        End If
            '    Else
            '        If vo.asset_status = "Storing" Then
            '            cmd.Parameters.AddWithValue("?ModiType", "4")
            '        Else
            '            cmd.Parameters.AddWithValue("?ModiType", ModiType)
            '        End If
            '    End If
            'End If
            cmd.Parameters.AddWithValue("?ModiType", "0")

            cmd.Parameters.AddWithValue("?SeqNo", max)
            cmd.Parameters.AddWithValue("?ModiUID", vo.ModiUID)
            cmd.Parameters.AddWithValue("?ModiDate", DateTime.Now)

            If vo.assetdef_idChg Then
                cmd.Parameters.AddWithValue("?assetdef_id", vo.assetdef_id)
            End If
            If vo.asset_ownerChg Then
                cmd.Parameters.AddWithValue("?asset_owner", vo.asset_owner)
            End If
            If vo.asset_statusChg Then

                cmd.Parameters.AddWithValue("?asset_status", vo.asset_status)
            End If


            If vo.ClassChg Then
                cmd.Parameters.AddWithValue("?Class", vo.Class1)
            End If


            If vo.EXtChg Then
                cmd.Parameters.AddWithValue("?EXt", vo.EXt)
            End If
            If vo.User1Chg Then
                cmd.Parameters.AddWithValue("?User1", vo.User1)
            End If
            '========================
            If vo.DeptChg Then
                cmd.Parameters.AddWithValue("?Dept", vo.Dept)
            End If
            If vo.LocationChg Then
                cmd.Parameters.AddWithValue("?Location", vo.Location)
            End If

            If vo.ComputerNameChg Then
                cmd.Parameters.AddWithValue("?ComputerName", vo.ComputerName)
            End If

            If vo.ModelChg Then
                cmd.Parameters.AddWithValue("?Model", vo.Model)
            End If
            If vo.CPUChg Then
                cmd.Parameters.AddWithValue("?CPU", vo.CPU)
            End If


            If vo.FDDChg Then
                cmd.Parameters.AddWithValue("?FDD", vo.FDD)
            End If


            If vo.CD_RChg Then
                cmd.Parameters.AddWithValue("?CD_R", vo.CD_R)
            End If

            If vo.CD_RWChg Then
                cmd.Parameters.AddWithValue("?CD_RW", vo.CD_RW)
            End If
            If vo.MAC1Chg Then
                cmd.Parameters.AddWithValue("?MAC1", vo.MAC1)
            End If
            If vo.MAC2Chg Then
                cmd.Parameters.AddWithValue("?MAC2", vo.MAC2)
            End If
            If vo.PSChg Then
                cmd.Parameters.AddWithValue("?PS", vo.PS)
            End If

            If vo.NBLabelChg Then
                cmd.Parameters.AddWithValue("?NBLabel", vo.NBLabel)
            End If
            If vo.MailChg Then
                cmd.Parameters.AddWithValue("?Mail", vo.Mail)
            End If
            If vo.RemarkChg Then
                cmd.Parameters.AddWithValue("?Remark", vo.Remark)
            End If
            If vo.OSChg Then
                cmd.Parameters.AddWithValue("?OS", vo.OS)
            End If
            If vo.HDDChg Then
                cmd.Parameters.AddWithValue("?HDD", vo.HDD)
            End If
            If vo.RAMChg Then
                cmd.Parameters.AddWithValue("?RAM", vo.RAM)
            End If
            If vo.UsingTypeChg Then
                cmd.Parameters.AddWithValue("?UsingType", vo.UsingType)
            End If

            If vo.MonitorSizeChg Then
                cmd.Parameters.AddWithValue("?MonitorSize", vo.MonitorSize)
            End If
            If vo.FactoryChg Then
                cmd.Parameters.AddWithValue("?Factory", vo.Factory)
            End If

            If vo.storehouseChg Then
                cmd.Parameters.AddWithValue("?storehouse", vo.storehouse)
                field1 += ",?storehouse"
            End If
            If vo.StoreLocationChg Then
                cmd.Parameters.AddWithValue("?StoreLocation", vo.StoreLocation)
            End If

            If vo.UsingType2Chg Then
                cmd.Parameters.AddWithValue("?UsingType2", vo.UsingType2)
            End If

            If vo.HouseIDChg Then
                cmd.Parameters.AddWithValue("?HouseID", vo.HouseID)
            End If

            If vo.OtherRemarkChg Then
                cmd.Parameters.AddWithValue("?OtherRemark", vo.OtherRemark)
            End If
            If vo.Asset_CostChg Then
                cmd.Parameters.AddWithValue("?Asset_Cost", vo.Asset_Cost)
            End If
            If vo.UsingDescChg Then
                cmd.Parameters.AddWithValue("?UsingDesc", vo.UsingDesc)
            End If

            ''=================================================5/10
            If dr("assetdef_id").ToString.Trim <> vo.assetdef_id.Trim Then

                cmd.Parameters.AddWithValue("?assetdef_idChg", "Y")
            End If
            If dr("asset_owner").ToString.Trim <> vo.asset_owner.Trim Then
                cmd.Parameters.AddWithValue("?asset_ownerChg", "Y")
            End If
            If dr("asset_status").ToString.Trim <> vo.asset_status.Trim Then

                cmd.Parameters.AddWithValue("?asset_statusChg", "Y")
            End If



            If dr("Class").ToString.Trim <> vo.Class1.Trim Then
                cmd.Parameters.AddWithValue("?ClassChg", "Y")
            End If



            If dr("EXt").ToString.Trim <> vo.EXt.Trim Then

                cmd.Parameters.AddWithValue("?EXtChg", "Y")
            End If
            If dr("User1").ToString.Trim <> vo.User1.Trim Then

                cmd.Parameters.AddWithValue("?User1Chg", "Y")
            End If
            If dr("Dept").ToString.Trim <> vo.Dept.Trim Then

                cmd.Parameters.AddWithValue("?DeptChg", "Y")
            End If
            If dr("Location").ToString.Trim <> vo.Location.Trim Then

                cmd.Parameters.AddWithValue("?LocationChg", "Y")
            End If

            If dr("ComputerName").ToString.Trim <> vo.ComputerName.Trim Then

                cmd.Parameters.AddWithValue("?ComputerNameChg", "Y")
            End If

            If dr("Model").ToString.Trim <> vo.Model.Trim Then

                cmd.Parameters.AddWithValue("?ModelChg", "Y")
            End If
            If dr("CPU").ToString.Trim <> vo.CPU.Trim Then

                cmd.Parameters.AddWithValue("?CPUChg", "Y")
            End If


            If dr("FDD").ToString.Trim <> vo.FDD.Trim Then

                cmd.Parameters.AddWithValue("?FDDChg", "Y")
            End If


            If dr("CD_R").ToString.Trim <> vo.CD_R.Trim Then

                cmd.Parameters.AddWithValue("?CD_RChg", "Y")
            End If

            If dr("CD_RW").ToString.Trim <> vo.CD_RW.Trim Then

                cmd.Parameters.AddWithValue("?CD_RWChg", "Y")
            End If
            If dr("MAC1").ToString.Trim <> vo.MAC1.Trim Then

                cmd.Parameters.AddWithValue("?MAC1Chg", "Y")
            End If
            If dr("MAC2").ToString.Trim <> vo.MAC2.Trim Then

                cmd.Parameters.AddWithValue("?MAC2Chg", "Y")
            End If
            If dr("PS").ToString.Trim <> vo.PS.Trim Then

                cmd.Parameters.AddWithValue("?PSChg", "Y")
            End If

            If dr("NBLabel").ToString.Trim <> vo.NBLabel.Trim Then

                cmd.Parameters.AddWithValue("?NBLabelChg", "Y")
            End If

            If dr("Remark").ToString.Trim <> vo.Remark.Trim Then

                cmd.Parameters.AddWithValue("?RemarkChg", "Y")
            End If
            If dr("OS").ToString.Trim <> vo.OS.Trim Then

                cmd.Parameters.AddWithValue("?OSChg", "Y")
            End If
            If dr("HDD").ToString.Trim <> vo.HDD.Trim Then

                field1 += ",?HDDChg"
                cmd.Parameters.AddWithValue("?HDDChg", "Y")
            End If
            If dr("RAM").ToString.Trim <> vo.RAM.Trim Then

                cmd.Parameters.AddWithValue("?RAMChg", "Y")
            End If
            If dr("UsingType").ToString.Trim <> vo.UsingType.Trim Then

                cmd.Parameters.AddWithValue("?UsingTypeChg", "Y")
            End If

            If dr("MonitorSize").ToString.Trim <> vo.MonitorSize.Trim Then

                cmd.Parameters.AddWithValue("?MonitorSizeChg", "Y")
            End If
            If dr("Factory").ToString.Trim <> vo.Factory.Trim Then

                cmd.Parameters.AddWithValue("?FactoryChg", "Y")
            End If

            If dr("storehouse").ToString.Trim <> vo.storehouse.Trim Then

                cmd.Parameters.AddWithValue("?storehouseChg", "Y")
            End If

            If dr("StoreLocation").ToString.Trim <> vo.StoreLocation.Trim Then

                cmd.Parameters.AddWithValue("?StoreLocationChg", "Y")
            End If

            If dr("UsingType2").ToString.Trim <> vo.UsingType2.Trim Then

                cmd.Parameters.AddWithValue("?UsingType2Chg", "Y")
            End If

            If dr("HouseID").ToString.Trim <> vo.HouseID.Trim Then

                cmd.Parameters.AddWithValue("?HouseIDChg", "Y")
            End If
            If dr("OtherRemark").ToString.Trim <> vo.OtherRemark.Trim Then

                cmd.Parameters.AddWithValue("?OtherRemarkChg", "Y")
            End If

            If dr("Asset_Cost").ToString.Trim <> vo.Asset_Cost.Trim Then

                cmd.Parameters.AddWithValue("?Asset_CostChg", "Y")
            End If

            If dr("UsingDesc").ToString.Trim <> vo.UsingDesc.Trim Then

                cmd.Parameters.AddWithValue("?UsingDescChg", "Y")
            End If


            cmd.ExecuteNonQuery()
            con.Close()
        Catch ex As Exception
            con.Close()
            Throw (New Exception(dr("asset_serialNo").ToString + ":" + ex.Message))
        Finally


        End Try


    End Sub

    Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton2.Click
        Dim dt As DataTable
        Dim dao As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO("AUOOAMS")
        dt = dao.GetAssetData("", "", "", "", "", "", "", "", "")
        Response.Write(dt.Rows.Count.ToString + "</br>")
        Response.Flush()
    End Sub
End Class
